<!--<div class='row-fluid'>
    <div class='span6'>
        <h3>Próximo check-in</h3>
        <form class="well">
            <div>
                <label>Nombre</label>
                <input type="text" class="span12" value='<?php echo '[' . $view->nextPoint['pointCode'] . '] ' . $view->nextPoint['pointName']; ?>'/>
                <label>Dirección</label>
                <textarea class="span12">

                </textarea>
                <div class='row-fluid'>
                    <div class="span6">
                        <label>Programación</label>
                        <input type="text" class="input-medium" value='<?php echo $view->nextPoint['route_date_format']; ?>'/>
                    </div>
                </div>
                <button type="button" class="btn btn-mini btn-primary pull-right startRoute">
                    <i class="icon-check icon-white"></i>
                    Check-in
                </button>
            </div>
        </form>
    </div>
</div>-->
<div class='row-fluid'>
    <h3>Paquetes</h3>
    <table class="table table-bordered table-condensed table-hover" id='packages'>
        <thead>
            <tr>
                <th>#</th>
                <th>Nombre</th>
                <th>Cantidad</th>
                <th>Peso</th>
                <th>Ancho x Alto x Profundidad</th>
                <th>Acción</th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($view->packages as $key => $package) :;
                $classStatusShipping = '';
                switch ($package['status_shipping'])
                {
                    case 0: // No se ha analizado
                        $classStatusShipping = '';
                        break;
                    case 1: // Aceptado
                        $classStatusShipping = 'success';
                        break;
                    case 2: // Aceptado, con observación
                        $classStatusShipping = 'warning';
                        break;
                    case 3: // Rechazado
                        $classStatusShipping = 'error';
                        break;
                }
                ?>
                <tr class='<?php echo $classStatusShipping; ?>' pkId='<?php echo $package['id']; ?>' namePackage='<?php echo $package['namePackage']; ?>' namePackage='<?php echo $package['namePackage']; ?>' numPackages='<?php echo $package['num_package']; ?>'>
                    <td class='hidden-phone'><?php echo $key + 1; ?></td>
                    <td class="text-left">
                        <?php if ($package['is_shipping'] === true): ?>
                            <button data-toggle="tooltip" class="btn btn-small btn-primary hidden-phone" type="button" title='Recolectar paquete'>
                                <i class="icon-arrow-up icon-white" title="Recolección"></i>
                            </button>
                        <?php else : ?>
                            <button data-toggle="tooltip" class="btn btn-small btn-info hidden-phone" type="button" title='Entregar paquete'>
                                <i class="icon-arrow-down icon-white" title="Entrega"></i>
                            </button>
                        <?php endif; ?>
                        <?php echo $package['namePackage']; ?>
                    </td>
                    <td class="text-right">
                        <span class="input-append">
                            <input class="text-right input-mini" disabled="disabled" type="text" value="<?php echo $package['num_package']; ?>">
                            <span class="add-on"><abbr title="Unidades">u</abbr></span>
                        </span>
                    </td>
                    <td class="text-right">
                        <span class="input-append">
                            <input class="text-right input-mini" disabled="disabled" type="text" value="<?php echo $package['weight']; ?>">
                            <span class="add-on"><abbr title="Kilogramos">Kg</abbr></span>
                        </span>
                    </td>
                    <td class="text-right">
                        <span class="input-append">
                            <input class="text-right input-small" disabled="disabled" type="text" value="<?php echo $package['width'] . ' x ' . $package['height'] . ' x ' . $package['depth']; ?>">
                            <span class="add-on"><abbr title="Centimetros">Cm</abbr></span>
                        </span>
                    </td>
                    <td class="text-left span3 acciones">
                        <?php if ($package['status_shipping'] == 0): ?>
                            <?php
                            $tipOk = 'Aceptar entrega / recolección de paquetes.';
                            $tipWarning = 'Acepto entrega / recolección, pero tengo una observación.';
                            $tipRechazo = 'Rechazo la entrega / recolecci[on de paquetes.';
                            ?>
                            <span class='span3'>
                                <button data-toggle="tooltip" class="btn btn-success" type="button" title='<?php echo $tipOk; ?>'>
                                    <i class="icon-ok icon-white" title="Recolección"></i>
                                </button>
                            </span>
                            <span class='span3'>
                                <button data-toggle="tooltip" class="btn btn-warning" type="button" title='<?php echo $tipWarning; ?>'>
                                    <i class="icon-comment icon-white" title="Recolección"></i>
                                </button>
                            </span>
                            <span class='span3'>
                                <button data-toggle="tooltip" class="btn btn-danger" type="button" title='<?php echo $tipRechazo; ?>'>
                                    <i class="icon-remove  icon-white" title="Recolección"></i>
                                </button>
                            </span>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<style type="text/css">
    table#packages td span.input-append
    {
        margin: 0px;
    }
    table#packages td.text-right
    {
        text-align: right;
    }
    table#packages td.text-center
    {
        text-align: center;
    }
    table#packages tr.success td.acciones button
    {
        display: none;
    }
    table#packages tr.warning td.acciones button
    {
        display: none;
    }
    table#packages tr.warning td.acciones button
    {
        display: none;
    }
</style>
<script type="text/javascript">
    $(document).ready(function() {
        var trSeleccionada = null;
        $('#packages button[data-toggle]').tooltip();

        $('#packages td.acciones button.btn-success').click(function() {
            trSeleccionada = $(this).parents('tr');
            $("#dlgSuccess").dialog({
                resizable: false,
                width: '70%',
                modal: true,
                buttons: {
                    "Acepto": function() {
                        var id = trSeleccionada.attr('pkId');
                        $.post(urlSuccess, {id: id}, function(success) {
                            if (success === true) {
                                trSeleccionada.addClass('success');
                                trSeleccionada.find('td.acciones').html('<stronng>OK</strong>');
                                $("#dlgSuccess").dialog("close");
                            }
                        }, 'json');
                    },
                    "Cancelar": function() {
                        $(this).dialog("close");
                    }
                }
            });
        });
        $('#packages td.acciones button.btn-warning').click(function() {
            trSeleccionada = $(this).parents('tr');
            $("#dlgWarning").dialog({
                resizable: false,
                width: '70%',
                modal: true,
                buttons: {
                    "Acepto con observación": function() {
                        var id = trSeleccionada.attr('pkId');
                        var obs = $('#obsWarning').val();
                        $.post(urlWarning, {id: id, obs: obs}, function(success) {
                            if (success === true) {
                                trSeleccionada.addClass('warning');
                                trSeleccionada.find('td.acciones').html(obs);
                                $("#dlgWarning").dialog("close");
                            }
                        }, 'json');
                    },
                    "Cancelar": function() {
                        $(this).dialog("close");
                    }
                }
            });
        });

        $('#packages td.acciones button.btn-danger').click(function() {
            trSeleccionada = $(this).parents('tr');
            $("#dlgDanger").dialog({
                resizable: false,
                width: '70%',
                modal: true,
                buttons: {
                    "Rechazo": function() {
                        var id = trSeleccionada.attr('pkId');
                        var obs = $('#obsDanger').val();
                        $.post(urlDanger, {id: id, obs: obs}, function(success) {
                            if (success === true) {
                                trSeleccionada.addClass('error');
                                trSeleccionada.find('td.acciones').html(obs);
                                $("#dlgDanger").dialog("close");
                            }
                        }, 'json');
                    },
                    "Cancelar": function() {
                        $(this).dialog("close");
                    }
                }
            });
        });
    });
</script>
<div id='dlgSuccess' style='display: none' title='Aceptar'>
    <div>
        Recolecto / entrego el(los) paquete(s) en buena(s) condición(es) y verifique 
        que cumple(n) con el(los) peso(s) y la(s) medida(s) indicadas.
    </div>
</div>
<div id='dlgWarning' style='display: none' title='Acepto con observación'>
    <div>
        <label>Observación</label>
        <textarea id='obsWarning' style='width: 100%'></textarea>
    </div>
</div>
<div id='dlgDanger' style='display: none' title='Rechazo'>
    <div>
        <label>Observación</label>
        <textarea id='obsDanger' style='width: 100%'></textarea>
    </div>
</div>
